package com.world.rickcloudendpoint.service.net.session;

import com.world.rickcloudendpoint.message.AbstractNetMessage;

/**
 * @description: 封装会话的业务逻辑
 * @author: jlsong
 * @date: 2021/12/23 23:33:17
 * @version: 1.0
 */
public interface ISession {

    /**
     * 判断当前会话是否处于连接状态
     *
     * @return
     */
    boolean isConnected();

    /**
     * 自定义消息回复
     * @param msg 消息
     */
    void write(AbstractNetMessage msg) throws Exception;

    /**
     * 立即关闭连接
     */
    void close(boolean immediately);

    /**
     * 出现异常时是否关闭连接
     *
     * @return
     */
    boolean closeOnException();

    /**
     * 字节数组消息回复
     * @param msg 消息
     * @throws Exception
     */
    void write(byte[] msg) throws Exception;
}
